package com.bw.aop;

import com.alibaba.fastjson.JSON;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAop {


    @Around("execution(* com.bw.service.*.*(..))")
    public Object aop(ProceedingJoinPoint joinPoint) throws Throwable {
        //打印方法名称及方法执行时间
        String name = joinPoint.getSignature().getName();
        System.out.println("方法名是 " + name);
        Object[] args = joinPoint.getArgs();
        System.out.println("入参是" + JSON.toJSONString(args));

        long l = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();//执行原方法
        long l2 = System.currentTimeMillis();

        System.out.println("执行时间是 " + (l2 - l));

        System.out.println("返回值是" + JSON.toJSONString(proceed));
        return proceed;

    }
}
